package com.zhong;

import com.zhong.po.User;
import org.junit.Test;

/**
 * 获取class
 */
public class ClassDemo1 {

    // 获取class
    @Test
    public void demo1() throws Exception{
        Class<?> clazz1 = Class.forName("com.zhong.po.User");
        Class<User> clazz2 = User.class;
        Class<? extends User> clazz3 = new User().getClass();
        System.err.println(clazz1);
        System.err.println(clazz2);
        System.err.println(clazz3);
    }

    //Class 其它API
    @Test
    public void demo2() throws Exception{
        Class<User> clazz1 = User.class;
        //获取实例
        User user = (User) clazz1.newInstance();

        //获取父类class
        Class<?> superclass = clazz1.getSuperclass();
        System.err.println(superclass);


        //获取全路径名
        String name = clazz1.getName();
        System.err.println(name);
    }

}
